package org.xlp.base.application.base;

import org.xlp.db.tableoption.annotation.XLPColumn;
import org.xlp.db.tableoption.annotation.XLPId;
import org.xlp.db.tableoption.xlpenum.DataType;
import org.xlp.javabean.annotation.FieldName;
import org.xlp.utils.XLPStringUtil;

import java.io.Serializable;

/**
 * Create by xlp on 2021/3/26
 *
 * 基本实体抽象类，抽象几个基本属性
 */
public abstract class BaseEntity implements CreatedInfo, Serializable, Cloneable, ICovert{
   private static final long serialVersionUID = -5746897510175841125L;

   @FieldName(mark = "主键，唯一标识")
   @XLPId(columnName = "id", descriptor = "主键，唯一标识")
   private Serializable id;

    @FieldName(mark = "类标识")
    @XLPColumn(columnName = "classId", dataType = DataType.VARCHAR,
           length = 32, isNull = false, descriptor = "类标识", maxLength = 32)
   private String classId;

    @FieldName(mark = "最近更新时间")
    @XLPColumn(columnName = "updateTime", dataType = DataType.BIGINT,
            descriptor = "最近更新时间", isNull = false)
    private Long updateTime;

    @FieldName
    @XLPColumn(columnName = "createTime", dataType = DataType.BIGINT,
            descriptor = "创建时间", isNull = false)
    private Long createTime;

    @FieldName(mark = "创建人id")
    @XLPColumn(columnName = "creatorId", dataType = DataType.VARCHAR,
            length = 64, descriptor = "创建人id")
    private String creatorId;

    @FieldName(mark = "最近更新人id")
    @XLPColumn(columnName = "updatedId", dataType = DataType.VARCHAR,
            length = 64, descriptor = "最近更新人id")
    private String updatedId;

    @Override
    public Long getUpdateTime() {
        return updateTime;
    }

    @Override
    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public Long getCreateTime() {
        return createTime;
    }

    @Override
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    @Override
    public String getCreatorId() {
        return creatorId;
    }

    @Override
    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    @Override
    public String getUpdatedId() {
        return updatedId;
    }

    @Override
    public void setUpdatedId(String updatedId) {
        this.updatedId = updatedId;
    }

    /**
     * 获取id
     *
     * @return
     */
    public Serializable getId() {
        return id;
    }

    /**
     * 设置id
     *
     * @param id
     */
    public void setId(Serializable id) {
        this.id = id;
    }

    /**
     * 获取classId
     *
     * @return
     */
    public String getClassId() {
        if (XLPStringUtil.isEmpty(classId)){
            return this.getClass().getSimpleName();
        }
        return classId;
    }

    /**
     * 设置classId
     *
     * @param classId
     */
    public void setClassId(String classId) {
        this.classId = classId;
    }

    @Override
    public BaseEntity clone() {
        try {
            return (BaseEntity) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String toString() {
        return "BaseEntity{" +
                "id=" + id +
                ", classId='" + classId + '\'' +
                ", updateTime=" + updateTime +
                ", createTime=" + createTime +
                ", creatorId='" + creatorId + '\'' +
                ", updatedId='" + updatedId + '\'' +
                '}';
    }
}
